<template>
  <div id="VIP_index" class="all">
    <el-breadcrumb separator="/">
      <el-breadcrumb-item>首页</el-breadcrumb-item>
      <el-breadcrumb-item>库存管理 </el-breadcrumb-item>
      <el-breadcrumb-item>出库明细</el-breadcrumb-item> 
    </el-breadcrumb>
    
    <br>

    
    <div class="table-container">
      <!-- <el-descriptions title="" class="custom-descriptions"></el-descriptions> -->
      <span style="margin-right: 91%;padding: 10px;"><b>出库查询</b></span>
      <el-divider class="custom-divider"></el-divider>
      <el-form :model="selform" ref="form">
        <el-row>
        <el-col :span="6">
          <el-input v-model="selform.ID" style="width: 95%;padding: 10px;" placeholder="购买订单编号" />
        </el-col>
        <el-col :span="6">
          <el-input v-model="selform.userName" style="width: 95%;padding: 10px;" placeholder="用户名" />
        </el-col>
        <el-col :span="6">
            <el-date-picker v-model="selform.time" type="datetimerange" :picker-options="pickerOptions" range-separator="至"
                            start-placeholder="开始日期" end-placeholder="结束日期" style="width: 95%;margin:10px;" align="right"></el-date-picker>
        </el-col>
        <el-col :span="4" style="text-align: center;padding: 8px 20px;">
          <el-button type="primary" style="font-size: 16px;" @click="submitselMessage"> 搜索</el-button>

          <el-dialog title="订单信息详情" :visible.sync="showMessage" @close="closeShowMessage" :close-on-click-modal="false">
            <el-table :data="goodlist" style="width: 100%" size="medium">
              <el-table-column width="250" prop="goodName" label="商品名称"></el-table-column>
              <el-table-column width="150" prop="number" label="数量"></el-table-column>
              <el-table-column width="150" prop="price" label="单价/元"></el-table-column>
              <el-table-column width="150" prop="totalprice" label="总价/元"></el-table-column>
            </el-table>
            <div slot="footer" class="dialog-footer">
              <el-button @click="closeShowMessage">返 回</el-button>
            </div>
          </el-dialog>

          <el-dialog title="更新购买订单信息" :visible.sync="updateMessage" @close="closeUpdateMessage" :close-on-click-modal="false">
            <el-form :model="updateform" ref="form">
              <el-form-item label="商品名称" :label-width="formLabelWidth" prop="goodName">
                <el-input v-model="updateform.goodName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="用户" :label-width="formLabelWidth" prop="username">
                <el-input v-model="updateform.userName" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="数量" :label-width="formLabelWidth">
                <el-input v-model="updateform.number" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="入库时间" :label-width="formLabelWidth">
                <!-- <el-input v-model="updateform.time" autocomplete="off"></el-input> -->
                <el-date-picker
                  v-model="updateform.time"
                  type="datetime"
                  placeholder="选择日期时间"
                  align="right"
                  style="width: 100%;"
                  :picker-options="pickerOptions">
                </el-date-picker>
              </el-form-item>
            </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button @click="closeUpdateMessage">取 消</el-button>
                <el-button type="primary" @click="submitUpdateMessage">确 定</el-button>
              </div>
          </el-dialog>



        </el-col>
      </el-row>
      </el-form>
    </div>
    
    <br>
    

    <!--表格数据-->
    <div class="table-container">
      <span style="margin-right: 91%;padding: 10px;"><b>出库信息</b></span>
      <el-divider class="custom-divider"></el-divider>
      <el-table :data="maindata" style="width: 100%" size="medium">
        <el-table-column prop="ID" width="150" label="购买订单编号"> </el-table-column>
        <el-table-column width="200" prop="userName" label="用户名"></el-table-column>
        <el-table-column width="150" prop="total" label="总金额/元"></el-table-column>
        <el-table-column width="150" prop="paid" label="支付金额/元"></el-table-column>
        <el-table-column width="200" prop="time" label="购买时间">
          <template slot-scope="scope">
                {{ decoder(scope.row.time) }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="320" fixed="right">
          <template v-slot="scope">
            <el-button style="font-size: 16px" type="primary" @click="openShowMessage(scope.row)"> 订单详情</el-button>
            <!-- <el-button style="font-size: 16px" type="success" @click="openUpdateMessage(scope.row)"> 修改</el-button> -->
            <el-button style="font-size: 16px" type="danger" @click="deleteOpen(scope.row)"> 删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      background
      layout="total, prev, pager, next, jumper"
      :total="400">
      </el-pagination>
    </div>
  </div>
</template>

<script>
export default {
  data() {
      return {
        maindata:[
        {
          ID:"1",
          userName:"Frevoid",
          total:"100",
          paid:"90",
          time:"2023-12-31T12:32:00.210Z"
        },
        {
          ID:"2",
          userName:"huangkang",
          total:"580",
          paid:"580",
          time:"2024-01-01T09:49:51.000Z"
        },
        ],
        goodlist:[
          {
            goodName: '农夫山泉',
            number: '1',
            price: '2',
            totalprice: '2',
          },
          {
            goodName: '保温杯',
            number: '1',
            price: '20',
            totalprice: '20',
          },
          {
            goodName: '雨伞',
            number: '1',
            price: '30',
            totalprice: '30',
          }
          ],
        inputMessage: false,
        updateMessage:false,
        showMessage:false,
        selform:{
          ID:"",
          userName:"",
          time:"",
        },

        updateform:{
          ID:"",
          goodName:"",
          userName:"",
          number:"",
          time:"",
        },
        deleteform:{
          ID:"",
          userName:"",
          total:"",
          paid:"",
          time:"",
        },
        formLabelWidth: '80px',
        formLabelWidthTime: '85px'
      };
    },
  methods: {
      handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
      },

      decoder(time) {
        let arr = time.split("T");
        let str1 = arr[0];
        let str2 = arr[1].split("Z")[0].split(".")[0];
        let result = `${str1} ${str2}`;
        return result;
      },

      openUpdateMessage(row){
        this.updateform.ID = row.ID;
        this.updateform.goodName = row.goodName;
        this.updateform.userName = row.userName;
        this.updateform.number = row.number;
        this.updateform.time = row.time;
        this.updateMessage = true;
      },
      closeUpdateMessage() {
        this.updateMessage = false;
      },
      submitUpdateMessage() {
        alert('修改的提交信息为 ' + JSON.stringify(this.updateform));
        this.closeUpdateMessage();
        this.$message({
            type: "success",
            message: "修改成功!",
          });
      },

      submitselMessage() {
        alert('提交的搜索信息为 ' + JSON.stringify(this.selform));
      },

      deleteOpen(row) {
        this.deleteform.ID = row.ID;
        this.deleteform.userName = row.userName;
        this.deleteform.total = row.total;
        this.deleteform.paid = row.paid;
        this.deleteform.time = row.time;
        alert('本次删除的信息为 ' + JSON.stringify(this.deleteform));
        this.$confirm("此操作将删除该条订单信息, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true,
        })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
      },

      openShowMessage(){
        //获取对应订单数据
        this.showMessage = true;
        },
      closeShowMessage() {
        this.showMessage = false;
      },

      pickerOptions: {
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },


    },
};
</script>

<style>
.router-link-active {
  text-decoration: none;
}
.table-container {
  box-shadow: 0 0 4px 1px rgba(0, 0, 0, .12), 0 0 6px rgba(0, 0, 0, .12);
}
.custom-divider {
  margin: 4px 0; /* 调整 el-divider 的间距 */
}
.custom-descriptions {
  padding-left: 10px;
  margin-bottom: 0;
}
.all {
  line-height: 30px;
}

</style>